home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / windowInternal2.icl < prev    next >
Encoding:
Modula Implementation  |  1997-04-23  |  18.6 KB  |  478 lines  |  [TEXT/3PRM]

  1. implementation module windowInternal2;
  2.  
  3. import StdClass;
  4. import    StdInt, StdBool;
  5. import    pointer, structure, windows, quickdraw, controls;
  6. import    commonDef, windowAccess;
  7. from    Picture            import Rect_in_region;
  8. from    windowInternal    import Scroll_window, Align_thumb;
  9. from    windowOpen        import Open_window;
  10.  
  11.  
  12. WindowPtrupdateRgn :== 122;
  13.  
  14. //    Setting the PictureDomain of a window with scroll bars and zoom box.
  15.  
  16. Set_window_domain    :: !Window !PictureDomain !(UpdateFunction *s) !*s !Toolbox
  17.     ->    (!Window, !*s, !Toolbox);
  18. Set_window_domain window=:(wPtr, hBar, vBar, pict, updArea, zoom) domain=:((xMin,yMin),(xMax,yMax)) f s tb
  19. |    lx && ly    = Zoom_domain window domain dx` dy` s tb1;
  20. |    lx            = Zoom_domain window domain dx` h    s tb1;
  21. |    ly            = Zoom_domain window domain w    dy` s tb1;
  22.                 = Set_domain  window domain (hThumb, vThumb) f s tb3;
  23.     where {
  24.         (hControl, hScroll, hMax)    = hBar;
  25.         (vControl, vScroll, vMax)    = vBar;
  26.         (curSize, tb1)                = Window_size wPtr tb;
  27.         (w, h)                        = curSize;
  28.         (hThumb,  tb2)                = GetCtlValue hControl tb1;
  29.         (vThumb,  tb3)                = GetCtlValue vControl tb2;
  30.         dx                            = xMax - xMin;        dx`= dx + ScrollBarWidth;
  31.         dy                            = yMax - yMin;        dy`= dy + ScrollBarWidth;
  32.         ly                            = dy` < h;
  33.         lx                            = dx` < w;
  34.     };
  35.  
  36. Zoom_domain    :: !Window !PictureDomain !Int !Int *s !Toolbox -> (!Window, !*s, !Toolbox);
  37. Zoom_domain window=:(wPtr, hBar, vBar, pict, updArea, zoom) domain=:((xMin,yMin),(xMax,yMax)) w h s tb
  38.     =    ((wPtr, hBar`, vBar`, pict, updArea, (xMin, yMin)), s, tb4);
  39.     where {
  40.         (hControl, hScroll, hMax)    = hBar;
  41.         (vControl, vScroll, vMax)    = vBar;
  42.         hBar`                        = (hControl, hScroll, xMax);
  43.         vBar`                        = (vControl, vScroll, yMax);
  44.         tb1                            = SizeWindow wPtr w h False tb;
  45.         tb2                            = SetWindowZoomState wPtr (xMin, xMax) (yMin, yMax) tb1;
  46.         tb3                            = RearrangeControls w h hControl xMax vControl yMax tb2;
  47.         tb4                            = Update_window [((0,0),(w,h))] wPtr tb3;
  48.         w`                            = w - ScrollBarWidth;
  49.         h`                            = h - ScrollBarWidth;
  50.     };
  51.  
  52.  
  53. Set_domain :: !Window !PictureDomain !(!Int, !Int) !(UpdateFunction *s) !*s !Toolbox
  54.     ->    (!Window, !*s, !Toolbox);
  55. Set_domain window=:(wPtr,hBar,vBar,picture,updArea,zoom) domain=:((xMin,yMin),(xMax,yMax)) thumbs f s tb
  56.     =    Scroll_window window2 hThumb vThumb hThumb` vThumb` f s tb6;
  57.     where {
  58.         (hControl, hScroll, hMax)    = hBar;
  59.         (vControl, vScroll, vMax)    = vBar;
  60.         (hThumb, vThumb)            = thumbs;
  61.         (curSize, tb1)                = Window_size wPtr tb;
  62.         (w, h)                        = curSize;
  63.         tb2                            = SetWindowZoomState wPtr (xMin, xMax) (yMin, yMax) tb1;
  64.         tb3                            = SetCtlMin hControl xMin (SetCtlMax hControl xMax` tb2);
  65.         tb4                            = SetCtlMin vControl yMin (SetCtlMax vControl yMax` tb3);
  66.         w`                            = w - ScrollBarWidth;
  67.         h`                            = h - ScrollBarWidth;
  68.         xMax`                        = xMax - w`;
  69.         yMax`                        = yMax - h`;
  70.         (hThumb`, tb5)                = GetCtlValue hControl tb4;
  71.         (vThumb`, tb6)                = GetCtlValue vControl tb5;
  72.         zoom`                        = (hThumb`, vThumb`);
  73.         hBar`                        = (hControl, hScroll, xMax);
  74.         vBar`                        = (vControl, vScroll, yMax);
  75.         window2                        = (wPtr, hBar`, vBar`, picture, updArea, zoom`);
  76.     };
  77.  
  78.  
  79. //    Setting the PictureDomain of a fixed size window.
  80.  
  81. Change_fixed_window_domain :: !PictureDomain !WindowPtr !(WindowHandle s) !Toolbox
  82.     ->    (!WindowHandle s, !Toolbox);
  83. Change_fixed_window_domain    domain=:((hMin, vMin), (hMax, vMax)) prevWindow
  84.                             ( wDef    =:FixedWindow id pos` title d u as,
  85.                               window=:(wPtr, hBar, vBar, pict, updArea, zoom)) tb
  86. |    dh < r - l
  87. &&    dv < b - t`        = ((wDef, window), tb3);
  88.                     = Open_window wDef` prevWindow (DisposeWindow wPtr tb2);
  89.     where {
  90.         tb3                = Update_window [((0,0), (dh,dv))] wPtr (SizeWindow wPtr dh dv False tb2);
  91.         wDef`            = ScrollWindow id pos title
  92.                             (ScrollBar (Thumb hMin) (Scroll 10)) (ScrollBar (Thumb vMin) (Scroll 10))
  93.                             domain (WindowDefGetFinalMinimumSize wDef) (dh, dv) u as;
  94.         pos                = (x - WindowScreenBorder, y - (TitleBarWidth + WindowScreenBorder));
  95.         dh                = hMax - hMin;
  96.         dv                = vMax - vMin;
  97.         t`                = t + TitleBarWidth;
  98.         (x,y)            = glob;
  99.         (glob, tb2)        = InGrafport wPtr (LocalToGlobal (0,0)) tb1;
  100.         (l,t, r,b, tb1)    = QScreenRect tb;
  101.     };
  102.  
  103.  
  104. //    Growing windows.
  105.  
  106. Update_grow_window :: !WindowPtr !ControlHandle !Int !ControlHandle !Int
  107.         !UpdateArea !(!Int,!Int) !(!Int,!Int) !(!Int,!Int) !Toolbox
  108.     ->    (!Toolbox, !UpdateArea);
  109. Update_grow_window    wPtr hControl hScroll vControl vScroll updArea 
  110.                     oldSize=:(oldW,oldH) oldThumbs=:(oldHt,oldVt) newSize=:(newW,newH) tb
  111. |    oldHt - newHt > 0
  112. ||    oldVt - newVt > 0    = Update_grown_window wPtr tb2 wholeWindow [] [after];
  113. |    gw && gh            = Update_grown_window wPtr tb2 [((oldW`,0),(newW,oldH`)),((0,oldH`),newSize)]
  114.                                                 domain updArea;
  115. |    gw                    = Update_grown_window wPtr tb2 [((oldW`,0),newSize),((0,newH`),newSize)]
  116.                                                 domain updArea;
  117. |    gh                    = Update_grown_window wPtr tb2 [((0,oldH`),newSize),((newW`,0),newSize)]
  118.                                                 domain updArea;
  119.                         = Update_grown_window wPtr tb2 [((newW`,0),(newW,newH`)),((0,newH`),newSize)]
  120.                                                 domain updArea;
  121.     where {
  122.         wholeWindow    = [((0,0), newSize)];
  123.         domain        = SubGrowRect before after;
  124.         before        = (oldThumbs, (oldHt + oldW`, oldVt + oldH`));
  125.         after        = (newThumbs, (newHt + newW`, newVt + newH`));
  126.         newThumbs    = (newHt, newVt);
  127.         (newVt, tb2)= GetCtlValue vControl (AlignControl vControl vScroll tb1);
  128.         (newHt, tb1)= GetCtlValue hControl (AlignControl hControl hScroll tb);
  129.         oldW`        = oldW - ScrollBarWidth;
  130.         newW`        = newW - ScrollBarWidth;
  131.         oldH`        = oldH - ScrollBarWidth;
  132.         newH`        = newH - ScrollBarWidth;
  133.         gh            = newH > oldH;
  134.         gw            = newW > oldW;
  135.     };
  136.  
  137. Update_grown_window wPtr tb rects upd1 upd2
  138.     :==    (Update_window rects wPtr tb, AppendUpdateAreas upd1 upd2);
  139.  
  140. AlignControl :: !ControlHandle !Int !Toolbox -> Toolbox;
  141. AlignControl control scroll tb
  142.     =     SetCtlValue control (Align_thumb thumb min max scroll) tb3;
  143.     where {
  144.         (thumb, tb1)= GetCtlValue control tb;
  145.         (min,   tb2)= GetCtlMin   control tb1;
  146.         (max,   tb3)= GetCtlMax   control tb2;
  147.     };
  148.  
  149.  
  150. SubGrowRect    :: !Rectangle !Rectangle -> UpdateArea;
  151. SubGrowRect before=:(b1=:(bXmin, bYmin), b2=:(bXmax, bYmax))
  152.             after =:(a1=:(aXmin, aYmin), a2=:(aXmax, aYmax))
  153. |    bXmin == aXmin
  154. &&    bYmin == aYmin    = EqualLeftTopSubGrowRect before after r1 r2;
  155. |    bXmax == aXmax
  156. &&    bYmax == aYmax    = NoEmptyRectangles [r3, r4];
  157.                     = NoEmptyRectangles [r1, r2, r3, r4];
  158.     where {
  159.         r1= ((bXmax, bYmin), (aXmax, bYmax));
  160.         r2= ((bXmin, bYmax), a2);
  161.         r3= ((aXmin, bYmin), (bXmin, aYmax));
  162.         r4= (a1,             (aXmax, bYmin));
  163.     };
  164.  
  165. EqualLeftTopSubGrowRect    :: !Rectangle !Rectangle !Rectangle !Rectangle -> UpdateArea;
  166. EqualLeftTopSubGrowRect before=:(b1=:(bXmin, bYmin), b2=:(bXmax, bYmax))
  167.                         after =:(a1=:(aXmin, aYmin), a2=:(aXmax, aYmax)) rightArea downArea
  168. |    isRight && isDown    = NoEmptyRectangles [rightArea, downArea];
  169. |    isRight                = NoEmptyRectangles [rightArea];
  170. |    isDown                = NoEmptyRectangles [downArea];
  171.                         = [];
  172.     where {
  173.         isDown = aYmax > bYmax;
  174.         isRight= aXmax > bXmax;
  175.     };
  176.     
  177. NoEmptyRectangles :: !UpdateArea -> UpdateArea;
  178. NoEmptyRectangles [r=:((xMin, yMin), (xMax, yMax)) : rs]
  179. |    xMin == xMax || yMin == yMax    = rs`;
  180.                                     = [r : rs`];
  181.     where {
  182.         rs` = NoEmptyRectangles rs;
  183.     };
  184. NoEmptyRectangles rs = rs;
  185.  
  186. Update_window :: !UpdateArea !WindowPtr !Toolbox -> Toolbox;
  187. Update_window [] _ tb = tb;
  188. Update_window updArea wPtr tb
  189.     =     QSetPort port tb3;
  190.     where {
  191.         (port, tb1)    = QGetPort tb;
  192.         tb2            = QSetPort wPtr tb1;
  193.         tb3            = SetInvalRects updArea tb2;
  194.     };
  195.  
  196. SetInvalRects :: !UpdateArea !Toolbox -> Toolbox;
  197. SetInvalRects [((l,t),(r,b)) : rs] tb = SetInvalRects rs (InvalRect (l,t,r,b) tb);
  198. SetInvalRects rs tb = tb;
  199.     
  200. Update_val_window :: !UpdateArea !WindowPtr !Toolbox -> Toolbox;
  201. Update_val_window [] _ tb = tb;
  202. Update_val_window updArea wPtr tb
  203.     =     QSetPort port tb3;
  204.     where {
  205.         (port, tb1)    = QGetPort tb;
  206.         tb2            = QSetPort wPtr tb1;
  207.         tb3            = SetValidRects updArea tb2;
  208.     };
  209.  
  210. SetValidRects :: !UpdateArea !Toolbox -> Toolbox;
  211. SetValidRects [((l,t),(r,b)) : rs] tb = SetValidRects rs (ValidRect (l,t,r,b) tb);
  212. SetValidRects _ tb = tb;
  213.     
  214. RearrangeControl :: !ControlHandle !Int !Int !Int !Int !Int !Toolbox -> Toolbox;
  215. RearrangeControl control h v width height max tb
  216.     =     tb6;
  217.     where {
  218.         (address, tb1)    = LoadLong control tb;
  219.         tb2                = StoreByte (address + 16) 0 tb1;
  220.         tb3                = MoveControl    control h v tb2;
  221.         tb4                = SizeControl    control width height tb3;
  222.         tb5                = SetCtlMax    control max tb4;
  223.         tb6                = StoreByte (address + 16) 255 tb5;
  224.     };
  225.  
  226. RearrangeControls    :: !Int !Int !ControlHandle !Int !ControlHandle !Int !Toolbox -> Toolbox;
  227. RearrangeControls w h hControl hMax vControl vMax tb
  228.     =     RearrangeControl hControl (-1) (h - ScrollBarWidth) (w - 13) 16 hMax` (
  229.             RearrangeControl vControl (w - ScrollBarWidth) (-1) 16 (h - 13) vMax` tb);
  230.     where {
  231.         hMax`= hMax - (w - ScrollBarWidth);
  232.         vMax`= vMax - (h - ScrollBarWidth);
  233.     };
  234.  
  235. Do_grow_window    :: !Window !MinimumWindowSize !Int !Int !Toolbox -> (!Window, !Toolbox);
  236. Do_grow_window window=:(wPtr, hBar, vBar, pict, updArea, zoom) minSize h v tb
  237.     =     Do_grow_window2 window minSize h v size (hThumb, vThumb) (hMin, vMin) tb5;
  238.     where {
  239.         (hControl, hScroll, hMax)    = hBar;
  240.         (vControl, vScroll, vMax)    = vBar;
  241.         (size,  tb1)                    = Window_size wPtr tb;
  242.         (hMin,  tb2)                    = GetCtlMin    hControl tb1;
  243.         (vMin,  tb3)                    = GetCtlMin    vControl tb2;
  244.         (hThumb,tb4)                    = GetCtlValue hControl tb3;
  245.         (vThumb,tb5)                    = GetCtlValue vControl tb4;
  246.     };
  247.  
  248. Do_grow_window2 :: !Window !MinimumWindowSize !Int !Int !(!Int, !Int) !(!Int, !Int) !(!Int, !Int) !Toolbox
  249.     ->    (!Window, !Toolbox);
  250. Do_grow_window2    window=:(wPtr, hBar=:(hControl,hScroll,hMax), vBar=:(vControl,vScroll,vMax), pict, updArea, zoom)
  251.                 minSize=:(minW, minH) h v oldSize oldThumbs=:(hThumb,vThumb)
  252.                 domainTop=:(hMin,vMin) tb
  253. |    newW <> 0 && newH <> 0    = ((wPtr, hBar, vBar, pict, updArea1, zoom), tb2);
  254.                             = (window, tb1);
  255.     where {
  256.         (tb2, updArea1) =
  257.             Update_grow_window wPtr hControl hScroll vControl vScroll updArea oldSize oldThumbs newSize (
  258.                 RearrangeControls newW newH hControl hMax vControl vMax (
  259.                     SizeWindow wPtr newW newH False tb1));
  260.         (newW, newH)    = newSize;
  261.         (newSize, tb1)    = GrowWindow wPtr h v (minW`, minH`, maxW, maxH) tb;
  262.         minW`                = minW + ScrollBarWidth;
  263.         minH`                = minH + ScrollBarWidth;
  264.         maxW                = inc (hMax - hMin + ScrollBarWidth);
  265.         maxH                = inc (vMax - vMin + ScrollBarWidth);
  266.     };
  267.  
  268.  
  269. /*    UpdateArea handling. Naive version of merging update areas. 
  270.     Check if it's better to avoid overlapping rectangles.
  271. */
  272.  
  273. AppendUpdateAreas    :: !UpdateArea !UpdateArea -> UpdateArea;
  274. AppendUpdateAreas [y : ys]    xs = [y : AppendUpdateAreas ys xs];
  275. AppendUpdateAreas ys            xs = xs;
  276.  
  277.  
  278. //    Determine whether an update is required for this window.
  279.  
  280. WindowSetUpdateArea    :: !Rect !Window !Toolbox -> (!Window, !Toolbox);
  281. WindowSetUpdateArea (l,t,r,b) window=:(wPtr, hBar, vBar, pict, [], zoom) tb
  282. |    doUpdate    = ((wPtr, hBar, vBar, pict, updArea, zoom), tb13);
  283.                 = (window, tb13);
  284.     where {
  285.         (hControl, hScroll, hMax)    = hBar;
  286.         (vControl, vScroll, vMax)    = vBar;
  287.         (updRgn,    tb1)            = LoadLong (wPtr + WindowPtrupdateRgn) tb;
  288.         (updRgnRect,tb2)            = LoadLong updRgn tb1;
  289.         rect                        = 2 + updRgnRect;
  290.         (top,        tb3)            = LoadWord rect            tb2;
  291.         (left,        tb4)            = LoadWord (rect + 2)    tb3;
  292.         (bottom,    tb5)            = LoadWord (rect + 4)    tb4;
  293.         (right,        tb6)            = LoadWord (rect + 6)    tb5;
  294.         (vThumb,    tb7)            = GetCtlValue vControl    tb6;
  295.         (hThumb,     tb8)            = GetCtlValue hControl    tb7;
  296.         (locMax,     tb9)            = InGrafport wPtr (GlobalToLocal (right,bottom)) tb8;
  297.         (locMin,     tb10)            = InGrafport wPtr (GlobalToLocal (left, top)) tb9;
  298.         (locLeft,  locTop)            = locMin;
  299.         (locRight, locBot)            = locMax;
  300.         updArea                        = [(    (hThumb + locLeft,            vThumb + locTop),
  301.                                             (hThumb + Min r locRight ,    vThumb + Min b locBot))];
  302.         (rectMax,    tb11)            = InGrafport wPtr (LocalToGlobal (dec r,dec b)) tb10;
  303.         (rectMin,    tb12)            = InGrafport wPtr (LocalToGlobal (inc l,inc t)) tb11;
  304.         (doUpdate,    tb13)            = Rect_in_region (rectMin, rectMax) updRgn tb12;
  305.     };
  306. WindowSetUpdateArea _ window tb = (window, tb);
  307.  
  308.  
  309. //    Zooming windows.
  310.  
  311. Store_w_state_data :: !WindowPtr !Rect !Toolbox -> Toolbox;
  312. Store_w_state_data wPtr (left, top, right, bottom) tb
  313.     =    tb6;
  314.     where {
  315.         (h, tb1)    = LoadLong (wPtr + 130)    tb;
  316.         (dh,tb2)    = DereferenceHandle h    tb1;
  317.         s0            = (h, 8 + dh);
  318.         (s1,tb3)    = Append_word s0 top    tb2;
  319.         (s2,tb4)    = Append_word s1 left    tb3;
  320.         (s3,tb5)    = Append_word s2 bottom    tb4;
  321.         (_,tb6)        = Append_word s3 right    tb5;
  322.     };
  323.  
  324. SetWindowZoomState :: !WindowPtr !(!Int, !Int) !(!Int, !Int) !Toolbox -> Toolbox;
  325. SetWindowZoomState wPtr (hMin,hMax) (vMin,vMax) tb
  326.     =    Store_w_state_data wPtr (left,top, right,bottom) tb1;
  327.     where {
  328.         dX        = hMax - hMin + ScrollBarWidth;
  329.         dY        = vMax - vMin + ScrollBarWidth;
  330.         left    = sL + WindowScreenBorder;
  331.         top        = sT + WindowScreenBorder + MenuBarWidth + TitleBarWidth;
  332.         right    = Min (left + dX) (sR - WindowScreenBorder);
  333.         bottom    = Min (top  + dY) (sB - WindowScreenBorder);
  334.         (sL,sT, sR,sB, tb1) = QScreenRect tb;
  335.     };
  336.  
  337.  
  338. Zoom_window    :: !Window !Int !Int !Int !Toolbox -> (!Window, !Toolbox);
  339. Zoom_window window=:(wPtr, hBar, vBar, pict, updArea, zoom) h v whereMouse tb
  340.     |    doZoom    = Zoom_window_in_out window whereMouse globPos tb2;
  341.                 = (window, tb1);
  342.     where {
  343.         (doZoom,  tb1) = TrackBox wPtr h v whereMouse tb;
  344.         (globPos, tb2) = InGrafport wPtr (LocalToGlobal (h,v)) tb1;
  345.     };
  346.  
  347. Zoom_window_in_out :: !Window !Int !WindowPos !Toolbox -> (!Window, !Toolbox);
  348. Zoom_window_in_out window=:(wPtr, hBar, vBar, pict, updArea, zoom) InZoomOut globLoc tb
  349.     =     Zoom_window_out window (hThumb, vThumb) globLoc tb2;
  350.     where {
  351.         (hControl, hScroll, hMax)    = hBar;
  352.         (vControl, vScroll, vMax)    = vBar;
  353.         (hThumb, tb1)                = GetCtlValue hControl tb;
  354.         (vThumb, tb2)                = GetCtlValue vControl tb1;
  355.     };
  356. Zoom_window_in_out window=:(wPtr, hBar, vBar, pict, updArea, zoom) InZoomIn globLoc tb
  357.     =     Zoom_window_in window minH maxH minV maxV (hThumb, vThumb) globLoc tb6;
  358.     where {
  359.         (hControl, hScroll, hMax)    = hBar;
  360.         (vControl, vScroll, vMax)    = vBar;
  361.         (minH,  tb1)= GetCtlMin    hControl tb;        (minV,  tb4)= GetCtlMin    vControl tb3;
  362.         (maxH,  tb2)= GetCtlMax    hControl tb1;        (maxV,  tb5)= GetCtlMax    vControl tb4;
  363.         (hThumb,tb3)= GetCtlValue hControl tb2;        (vThumb,tb6)= GetCtlValue vControl tb5;
  364.     };
  365.  
  366. Zoom_window_out :: !Window !(!Int, !Int) !WindowPos !Toolbox -> (!Window, !Toolbox);
  367. Zoom_window_out window=:(wPtr, hBar, vBar, pict, updArea, zoom) zoom`=:(hThumb, vThumb) globLoc tb
  368.     =    ((wPtr, hBar, vBar, pict, updArea`, zoom`), tb8);
  369.     where {
  370.         (hControl, hScroll, hMax)    = hBar;
  371.         (vControl, vScroll, vMax)    = vBar;
  372.         (oldSize,  tb1)                = Window_size wPtr tb;
  373.         tb2                            = InGrafport2 wPtr (ZoomWindow wPtr InZoomOut True) tb1;
  374.         (newSize,  tb3)                = Window_size wPtr tb2;
  375.         (w, h)                        = newSize;
  376.         (globLoc`, tb4)                = InGrafport  wPtr (LocalToGlobal (0,0)) tb3;
  377.         tb5                            = RearrangeControls w h hControl hMax vControl vMax tb4;
  378.         (hThumb`, tb6)                = GetCtlValue hControl tb5;
  379.         (vThumb`, tb7)                = GetCtlValue vControl tb6;
  380.         (tb8, updArea`) =
  381.             ZoomOutUpdateArea wPtr globLoc globLoc` zoom` (hThumb`, vThumb`) oldSize newSize tb7;
  382.     };
  383.  
  384. ZoomOutUpdateArea :: !WindowPtr !WindowPos !WindowPos !(!Int, !Int) !(!Int, !Int) !(!Int, !Int)
  385.                      !(!Int, !Int) !Toolbox
  386.     ->    (!Toolbox, !UpdateArea);
  387. ZoomOutUpdateArea wPtr    oldLoc        =:(globX,    globY)
  388.                         newLoc        =:(globX`,    globY`)
  389.                         oldThumbs    =:(hThumb,    vThumb)
  390.                         newThumbs    =:(hThumb`,    vThumb`)
  391.                         oldSize        =:(oldW,    oldH)
  392.                         newSize        =:(newW,    newH) tb
  393. |    globX  <>  globX`    || globY  <>  globY`
  394. ||    hThumb <> hThumb`    || vThumb <> vThumb`
  395.     = (Update_window [((0,0),newSize)] wPtr tb,
  396.         [(newThumbs, (hThumb` + newW - ScrollBarWidth, vThumb` + newH - ScrollBarWidth))]);
  397. |    newW > oldW
  398.     = ZoomOutUpdateArea2 wPtr oldW oldH newW newH (oldW - ScrollBarWidth) newW True newThumbs tb;
  399.     = ZoomOutUpdateArea2 wPtr oldW oldH newW newH newW newW False newThumbs tb;
  400.  
  401. ZoomOutUpdateArea2 :: !WindowPtr !Int !Int !Int !Int !Int !Int !Bool !(!Int, !Int) !Toolbox
  402.     ->    (!Toolbox, !UpdateArea);
  403. ZoomOutUpdateArea2 wPtr oldW oldH newW newH updLeft updRight widthIncr (hT, vT) tb
  404.     | newH > oldH
  405.     =     ZoomUpdateArea wPtr updLeft 0 updRight oldH
  406.                             0 (oldH - ScrollBarWidth) newW newH widthIncr True  hT vT tb;
  407.     =     ZoomUpdateArea wPtr updLeft 0 updRight newH
  408.                             0 (newH - ScrollBarWidth) newW newH widthIncr False hT vT tb;
  409.  
  410. ZoomUpdateArea    :: !WindowPtr !Int !Int !Int !Int !Int !Int !Int !Int !Bool !Bool !Int Int !Toolbox
  411.     ->    (!Toolbox, !UpdateArea);
  412. ZoomUpdateArea wPtr    left1 top1 right1 bottom1
  413.                     left2 top2 right2 bottom2
  414.                     wIncr hIncr hThumb vThumb tb
  415. | wIncr && hIncr    = (Update_val_window [((0,0),(left1, top2))] wPtr tb, [r1, r2]);
  416. | wIncr                = (Update_window
  417.                             [((left1`,bottom1``), (left1,bottom1`))] wPtr
  418.                             (Update_val_window [((0,0),(left1, bottom1`))] wPtr tb), [r1]);
  419. | hIncr                = (Update_window 
  420.                             [((right1`,bottom1``),(right1,bottom1`))] wPtr
  421.                             (Update_val_window [((0,0),(right1,bottom1`))] wPtr tb), [r2]);
  422.                     = (tb, [(lt, lt)]);
  423.     where {
  424.         r1        = (lt,    (hThumb + right1`, vThumb + bottom1`));
  425.         r2        = ((hThumb + left2, vThumb + top2), (hThumb + right2`, vThumb + bottom2`));
  426.         right1`    = right1 - ScrollBarWidth;    bottom1` = bottom1  - ScrollBarWidth;
  427.         right2`    = right2 - ScrollBarWidth;    bottom2` = bottom2  - ScrollBarWidth;
  428.         left1`    = left1  - ScrollBarWidth;    bottom1``= bottom1` - ScrollBarWidth;
  429.         lt        = (hThumb + left1, vThumb + top1);
  430.     };
  431.  
  432. Zoom_window_in    :: !Window !Int !Int !Int !Int !(!Int, !Int) !WindowPos !Toolbox
  433.     ->    (!Window, !Toolbox);
  434. Zoom_window_in window=:(wPtr, hBar, vBar, pict, updArea, zoom) minH maxH minV maxV thumbs globLoc tb
  435.     =    ((wPtr, hBar, vBar, pict, updArea`, zoom), tb10);
  436.     where {
  437.         (hControl, hScroll, hMax)    = hBar;
  438.         (vControl, vScroll, vMax)    = vBar;
  439.         (oldH, oldV)                = zoom;
  440.         (oldSize, tb1)    = Window_size wPtr tb;
  441.         tb2                = InGrafport2 wPtr (ZoomWindow wPtr InZoomIn True) tb1;
  442.         (newSize, tb3)    = Window_size wPtr tb2;
  443.         (w, h)            = newSize;
  444.         (globLoc`, tb4)    = InGrafport wPtr (LocalToGlobal (0,0)) tb3;
  445.         tb5                = RearrangeControls w h hControl hMax vControl vMax tb4;
  446.         tb6                = Restore_thumb hControl oldH minH maxH tb5;
  447.         tb7                = Restore_thumb vControl oldV minV maxV tb6;
  448.         (newH, tb8)        = GetCtlValue hControl tb7;
  449.         (newV, tb9)        = GetCtlValue vControl tb8;
  450.         (tb10,updArea`)    =
  451.             ZoomInUpdateArea wPtr globLoc globLoc` thumbs (newH,newV) oldSize newSize tb9;
  452.     };
  453.  
  454. ZoomInUpdateArea :: !WindowPtr !WindowPos !WindowPos !(!Int, !Int) !(!Int, !Int) !(!Int, !Int)
  455.                             !(!Int, !Int) !Toolbox
  456.     ->    (!Toolbox, !UpdateArea);
  457. ZoomInUpdateArea wPtr    oldLoc        =:(globX,    globY)
  458.                         newLoc        =:(globX`,    globY`)
  459.                         oldThumbs    =:(hThumb,    vThumb)
  460.                         newThumbs    =:(hThumb`,    vThumb`)
  461.                         oldSize        =:(oldW,    oldH)
  462.                         newSize        =:(newW,    newH) tb
  463. |    newW > oldW
  464. ||    newH > oldH
  465.     =     ZoomOutUpdateArea wPtr oldLoc newLoc oldThumbs newThumbs oldSize newSize tb;
  466. |    globX  == globX`
  467. &&    globY  == globY`
  468. &&    hThumb == hThumb`
  469. &&    vThumb == vThumb`
  470.     =    (tb, [(newThumbs, newThumbs)]);
  471.     =    (Update_window [((0,0),newSize)] wPtr tb,
  472.          [(newThumbs, (hThumb` + newW - ScrollBarWidth, vThumb` + newH - ScrollBarWidth))]);
  473.  
  474. Restore_thumb :: !ControlHandle !Int !Int !Int !Toolbox -> Toolbox;
  475. Restore_thumb control thumb min max tb
  476. |    min <> max    = tb;
  477.                 = SetCtlValue control thumb tb;
  478.